﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FilstartupsREST.Models;

namespace FilstartupsREST.FILSTARTUPSService.rest.Controllers
{
    public class ForumController : Controller
    {
        FilStartUpsEntities cms_db = new FilStartUpsEntities();
        //
        // GET: /Forum/
        [HttpGet]
        public JsonResult GetForumTopic()
        {
            var forum = cms_db.Forums.OrderBy(f=>f.forumidPK)
                              .Where(f=>f.routingidFK.Equals(2))
                              .ToList();

            if (forum.Count() > 0 )
            {
                return Json(new { forum, success = true }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { forum=string.Empty}, JsonRequestBehavior.AllowGet);
            }
        }

        //Post Method Increment Views++ Database
        [HttpGet]
        public JsonResult ForumViews(string forumidPK)
        {
            int forumid = int.Parse(forumidPK);

            var forum = cms_db.Forums.Find(forumid);
            forum.views += 1;
            cms_db.SaveChanges();
            return Json(new { success = true }, JsonRequestBehavior.AllowGet);
        }
        
    }
}
